/*
 * Copyright 2008 Jens Meiss
 * 
 * Licensed under the Apache License, Version 2.0 (the "License");
 * you may not use this file except in compliance with the License. 
 * You may obtain a copy of the License at 
 * 
 * http://www.apache.org/licenses/LICENSE-2.0
 * 
 * Unless required by applicable law or agreed to in writing, software
 * distributed under the License is distributed on an "AS IS" BASIS,
 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
 * See the License for the specific language governing permissions and
 * limitations under the License.
 */
package com.googlecode.hmvc4java.component;

import com.googlecode.hmvc4java.IInitializeable;
import com.googlecode.hmvc4java.controller.IController;
import com.googlecode.hmvc4java.event.IEvent;
import com.googlecode.hmvc4java.event.IEventListener;

/**
 * This Interface defines a Component.
 * 
 * @author jens.meiss
 */
public interface IComponent extends IInitializeable, IEventListener {

	/**
	 * @return the parent Component or null if there is no parent Component
	 */
	public IComponent getParentComponent();

	/**
	 * @return the controller of the Component
	 */
	public IController getController();

	/**
	 * setter of the controller of the component
	 * 
	 * @param controller
	 */
	public void setController(IController controller);

	/**
	 * tests if the component contains a childComponent. The Component is
	 * identified by its Controller.
	 * 
	 * @param classOfController
	 * @return contains the component a child of the given Controller class
	 */
	public boolean containsChildComponent(
			Class<? extends IController> classOfController);

	/**
	 * tests if the component contains a childComponent. The Component is
	 * identified by a specific Controller instance.
	 * 
	 * @param controller
	 * @return
	 */
	public boolean containsChildComponent(IController controller);

	/**
	 * setter of the parentComponent property
	 * 
	 * @param component
	 */
	public void setParentComponent(IComponent component);

	/**
	 * fires a event upward in the hmvc-tree
	 * 
	 * @param event
	 */
	public void fireEventUp(IEvent event);

	/**
	 * fires a event downward in the hmvc-tree
	 * 
	 * @param event
	 */
	public void fireEventDown(IEvent event);

	/**
	 * adds a childComponent to the component
	 * 
	 * @param component
	 */
	public void addChildComponent(IComponent component);

	/**
	 * The Component receives events through this method
	 * 
	 * @param event
	 * @return was the event handled by the Component?
	 */
	public boolean receiveEvent(IEvent event);

	/**
	 * Adds an terminated Child to Component. The Component will remove the
	 * Child on the next event-handling
	 * 
	 * @param childComponent
	 */
	public void addTerminadtedChild(IComponent childComponent);

	/**
	 * Call this method to Terminate the Component.
	 */
	public void terminateComponent();

	/**
	 * This Method is called at the initialization of the Component
	 */
	public void initComponent();

}
